﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

public partial class UserList
{
    private string connectionstr = "";
    public string connectionString
    {
        get { return connectionstr; }
        set { connectionstr = value; }
    }

    /// <summary>
    /// return error message
    /// </summary>
    private string error = null;
    public string ErrorMessage
    {
        get { return error; }
    }

    /// <summary>
    /// Constructor.
    /// </summary>
    public UserList()
    {
        //
        // TODO: Add constructor logic here
        //
        //connectionstr = connectionstr; //WebConfigurationManager.ConnectionStrings["DBNhanSu"].ConnectionString;
    }

    /// <summary>
    /// overload constructor - with connectionstring
    /// Set the connectionString
    /// </summary>
    public UserList(string connectionstring)
    {
        connectionstr = connectionstring;
    }

    /// <summary>
    /// Load user with no condition
    /// </summary>
    /// <param name="commandtext"></param>
    /// <returns></returns>
    //public DataTable LoadUser(string commandtext,)
    //{
    //    DataTable tbl = new DataTable();
    //    DataProvider dp = new DataProvider(connectionstr);
    //    dp.CommandText = commandtext;
    //    dp.CommandType = CommandType.TableDirect;
    //    tbl = dp.GetDataTable();
    //    dp.CloseConnection();
    //    return tbl;
    //}

    /// <summary>
    /// Load the user list
    /// </summary>
    /// <param name="commandtext"></param>
    /// <param name="param"></param>
    /// <param name="value"></param>
    /// <returns></returns>
    public DataTable LoadUser(string commandtext, string[]param, object[] value)
    {
        DataTable tbl = new DataTable();
        DataProvider dp = new DataProvider(connectionstr);
        dp.CommandText = commandtext;
        dp.CommandType = CommandType.StoredProcedure;
        dp.ParameterCollection = param;
        dp.ValueCollection = value;
        tbl = dp.GetDataTable();
        dp.CloseConnection();
        return tbl;
    }

    /// <summary>
    /// Create and update the user list
    /// </summary>
    /// <param name="commandtext"></param>
    /// <param name="param"></param>
    /// <param name="value"></param>
    /// <returns></returns>
    public bool CreateUpdateUserList(string commandtext, string[] param, string[] value)
    {
        DataTable tbl = new DataTable();
        DataProvider dp = new DataProvider(connectionstr);
        dp.CommandText = commandtext;
        dp.CommandType = CommandType.StoredProcedure;
        dp.ParameterCollection = param;
        dp.ValueCollection = value;
        bool r = (dp.ExecuteNonQuery() > 0);
        dp.CloseConnection();
        return r;
    }
}
